<html>
<head><meta charset="utf-8"><title>issue 87319 · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html">issue 87319</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246867048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246867048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pierwill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246867048">(Jul 22 2021 at 15:58)</a>:</h4>
<p>Hi all! I'm hoping to give <a href="https://github.com/rust-lang/rust/issues/87319">https://github.com/rust-lang/rust/issues/87319</a> a try. I've contributed rustc API docs before, but never any real code. This one seems doable for a beginner (but maybe I'm wrong?). Any tips on where to start? Is this "Declaring a Lint" section in the dev guide relevant? <a href="https://rustc-dev-guide.rust-lang.org/diagnostics.html#declaring-a-lint">https://rustc-dev-guide.rust-lang.org/diagnostics.html#declaring-a-lint</a> Any help would be greatly appreciated.</p>



<a name="246868393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246868393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246868393">(Jul 22 2021 at 16:08)</a>:</h4>
<p><span class="user-mention" data-user-id="316352">@pierwill</span> yes, that's instructions for declaring. For implementing, take a look at <code>rustc_lint/builtin.rs</code>.</p>



<a name="246868434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246868434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246868434">(Jul 22 2021 at 16:09)</a>:</h4>
<p>oh it actually has an example in the docs and everything</p>



<a name="246868442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246868442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246868442">(Jul 22 2021 at 16:09)</a>:</h4>
<p><span class="user-mention" data-user-id="125294">@Aaron Hill</span> you've been busy <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="246868568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246868568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246868568">(Jul 22 2021 at 16:10)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> I don't think I wrote those docs, did I? :)</p>



<a name="246868597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246868597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246868597">(Jul 22 2021 at 16:10)</a>:</h4>
<p>you wrote the suggestion to use rustc_lint instead of lint_defs I think - maybe I got confused about the example</p>



<a name="246868692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246868692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246868692">(Jul 22 2021 at 16:11)</a>:</h4>
<p>I think somebody else commit that at my suggestion, maybe?</p>



<a name="246868709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246868709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246868709">(Jul 22 2021 at 16:11)</a>:</h4>
<p>ah, that's probably it</p>



<a name="246868825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246868825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246868825">(Jul 22 2021 at 16:12)</a>:</h4>
<p>anyway, back to implementing this particular lint</p>



<a name="246869883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246869883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246869883">(Jul 22 2021 at 16:20)</a>:</h4>
<p><span class="user-mention" data-user-id="316352">@pierwill</span> The escape sequence handling for string literals is handled here: <a href="https://github.com/rust-lang/rust/blob/1158367a6d60d3e2a8c68d6212a8007992b1dbf0/compiler/rustc_lexer/src/unescape.rs#L267">https://github.com/rust-lang/rust/blob/1158367a6d60d3e2a8c68d6212a8007992b1dbf0/compiler/rustc_lexer/src/unescape.rs#L267</a></p>



<a name="246870153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246870153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246870153">(Jul 22 2021 at 16:22)</a>:</h4>
<p>It looks like the issue lies in <a href="https://github.com/rust-lang/rust/blob/1158367a6d60d3e2a8c68d6212a8007992b1dbf0/compiler/rustc_lexer/src/unescape.rs#L300">https://github.com/rust-lang/rust/blob/1158367a6d60d3e2a8c68d6212a8007992b1dbf0/compiler/rustc_lexer/src/unescape.rs#L300</a> - we consider <code>\n</code> to be 'ascii whitespace'</p>



<a name="246870190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246870190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246870190">(Jul 22 2021 at 16:23)</a>:</h4>
<p>and will therefore skip over it after we encounter an escaped newline</p>



<a name="246872252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/246872252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pierwill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#246872252">(Jul 22 2021 at 16:39)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="125294">@Aaron Hill</span> ! I'll take a little time to wrap my head around this code, then probably (definitely) pop back in for more advice :)</p>



<a name="247003833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247003833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pierwill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247003833">(Jul 23 2021 at 16:59)</a>:</h4>
<p>How is this looking so far? Is an in impl block in this file the right place to implement the logic for the lint? <a href="https://github.com/rust-lang/rust/compare/master...pierwill:fix-87197-multiple-newline-lint?expand=1">https://github.com/rust-lang/rust/compare/master...pierwill:fix-87197-multiple-newline-lint?expand=1</a></p>



<a name="247004480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247004480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247004480">(Jul 23 2021 at 17:04)</a>:</h4>
<p>seems fine</p>



<a name="247005436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247005436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247005436">(Jul 23 2021 at 17:11)</a>:</h4>
<p>Won't the escaped newlines be absent from the generated symbols?</p>



<a name="247005624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247005624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247005624">(Jul 23 2021 at 17:12)</a>:</h4>
<p><span class="user-mention" data-user-id="255061">@Léo Lanteri Thauvin</span> I'm unclear what you're asking. In</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"\</span>

<span class="s">b"</span><span class="p">;</span><span class="w"></span>
</code></pre></div>
<p>a has the value <code>"\nb"</code> - only the first newline is removed</p>



<a name="247005673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247005673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247005673">(Jul 23 2021 at 17:13)</a>:</h4>
<p>oh err</p>



<a name="247005686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247005686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247005686">(Jul 23 2021 at 17:13)</a>:</h4>
<p>apparently it's the opposite and it has the value <code>"b"</code></p>



<a name="247005697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247005697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247005697">(Jul 23 2021 at 17:13)</a>:</h4>
<p>wow that almost seems more confusing to me</p>



<a name="247005704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247005704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247005704">(Jul 23 2021 at 17:13)</a>:</h4>
<p>Yes, but if you implement this as a lint pass you won't be able to know there was an escaped newline there?</p>



<a name="247005750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247005750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247005750">(Jul 23 2021 at 17:14)</a>:</h4>
<p>oh you mean this has to be an earlier pass in the lexer</p>



<a name="247005765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247005765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247005765">(Jul 23 2021 at 17:14)</a>:</h4>
<p>yes I think you're right</p>



<a name="247005829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247005829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247005829">(Jul 23 2021 at 17:14)</a>:</h4>
<p>Yes, sorry I meant that as an answer to the question</p>
<blockquote>
<p>Is an in impl block in this file the right place to implement the logic for the lint?</p>
</blockquote>



<a name="247005954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247005954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247005954">(Jul 23 2021 at 17:15)</a>:</h4>
<p><code>rustc_lexer</code> only splits the code input into tokens. Each token consists of the kind and the length. It doesn't actually interpret the token to form the final string.</p>



<a name="247009400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247009400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pierwill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247009400">(Jul 23 2021 at 17:42)</a>:</h4>
<p>Ah! Oh no, back to square one. :(  <span aria-label="innocent" class="emoji emoji-1f607" role="img" title="innocent">:innocent:</span></p>



<a name="247009479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247009479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pierwill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247009479">(Jul 23 2021 at 17:43)</a>:</h4>
<p>so <code>rustc_span::symbol::Symbol</code> won't give us the data we need at this point in compilation in rustc_lexer?</p>



<a name="247009605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247009605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pierwill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247009605">(Jul 23 2021 at 17:44)</a>:</h4>
<p>refering to the <code>symbol</code> field here: <br>
<a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/token/struct.Lit.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/token/struct.Lit.html</a></p>



<a name="247016122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247016122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247016122">(Jul 23 2021 at 18:41)</a>:</h4>
<p><span class="user-mention" data-user-id="316352">@pierwill</span> I believe the needed information gets thrown away by the lexer currently</p>



<a name="247016142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247016142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247016142">(Jul 23 2021 at 18:41)</a>:</h4>
<p>In the files that I linked earlier</p>



<a name="247016192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247016192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pierwill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247016192">(Jul 23 2021 at 18:41)</a>:</h4>
<p>ah! so maybe we do need to change that unescape logic before we can implement the lint?</p>



<a name="247016730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247016730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pierwill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247016730">(Jul 23 2021 at 18:47)</a>:</h4>
<p>or will I have to _go deeper_ <span aria-label="imp" class="emoji emoji-1f47f" role="img" title="imp">:imp:</span></p>



<a name="247025978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247025978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247025978">(Jul 23 2021 at 20:13)</a>:</h4>
<p>Is parsing/lexing too early in the compilation process to emit lints?</p>



<a name="247026060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247026060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247026060">(Jul 23 2021 at 20:13)</a>:</h4>
<p>(Nevermind, it has to be, we don't know the lint levels yet)</p>



<a name="247027528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247027528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247027528">(Jul 23 2021 at 20:26)</a>:</h4>
<p>yeah lints are a tcx thing</p>



<a name="247033166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247033166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247033166">(Jul 23 2021 at 21:11)</a>:</h4>
<p>We do have 'buffered lints' during expansion</p>



<a name="247041148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247041148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247041148">(Jul 23 2021 at 22:44)</a>:</h4>
<p>To avoid a large amount of refactoring, I think it might be reasonable to add some thread-local state in <code>rustc_lexer</code> to store information about any lints we want to emit</p>



<a name="247041165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247041165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247041165">(Jul 23 2021 at 22:45)</a>:</h4>
<p>and then emit them in <code>rustc_expand</code> or <code>rustc_middle</code></p>



<a name="247041245"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247041245" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247041245">(Jul 23 2021 at 22:46)</a>:</h4>
<p>Otherwise, you're going to need to pass down / return up something through lots of different APIs and crates</p>



<a name="247041255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247041255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247041255">(Jul 23 2021 at 22:46)</a>:</h4>
<p>e.g. <code>LitKind::from_lit_token</code> is not really set up to track or emit a lint</p>



<a name="247042280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247042280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247042280">(Jul 23 2021 at 23:02)</a>:</h4>
<p>Do we have crater data on just a hard error (panic! or whatever seems fine) yet? If it's tiny breakage might be ok without a lint....</p>



<a name="247047994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247047994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247047994">(Jul 24 2021 at 00:57)</a>:</h4>
<p>I wrote a scanner using proc_macro2 to tokenize all the source code on <a href="http://crates.io">crates.io</a>. It found about 41 packages that use this form of continuation. (Assuming I wrote it correctly.)  Skimming over some of them, I would say most are mistakes, though it is hard to say.</p>



<a name="247059596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247059596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247059596">(Jul 24 2021 at 06:41)</a>:</h4>
<p><span class="user-mention" data-user-id="125294">@Aaron Hill</span> I think it would be a better idea to put the lint code at the place where rustc_lexer is called than to use TLS.</p>



<a name="247461253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247461253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Anton Golov <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247461253">(Jul 28 2021 at 13:50)</a>:</h4>
<p>Looking at this in connection to <a href="https://github.com/rust-lang/rust/issues/87318">issue 87318</a>: it appears that unescape_literal is called from two places:</p>
<ol>
<li><a href="https://github.com/rust-lang/rust/blob/master/compiler/rustc_parse/src/lexer/mod.rs#L553-L582">https://github.com/rust-lang/rust/blob/master/compiler/rustc_parse/src/lexer/mod.rs#L553-L582</a> which does only validation and doesn't care about the result</li>
<li><a href="https://github.com/rust-lang/rust/blob/master/compiler/rustc_ast/src/util/literal.rs#L60-L69">https://github.com/rust-lang/rust/blob/master/compiler/rustc_ast/src/util/literal.rs#L60-L69</a> which builds the unescaped string itself.</li>
</ol>
<p>Currently, the callback takes a pair of <code>Range&lt;usize&gt;</code> and <code>Result&lt;char, EscapeError&gt;</code>.  Only the <code>EscapeError</code> is used in 1, and only the char is used in 2.<br>
As such, it looks like it would not be too much of a change to replace the <code>char</code> with a <code>Result&lt;char, EscapeLint&gt;</code> (or a named enum) and get the warnings out that way.  Alternatively, the whole thing could be split into two or even three callbacks; this would also make some sense since the <code>Range&lt;usize&gt;</code>  is only used for the error-reporting case.</p>



<a name="247462130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247462130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Anton Golov <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247462130">(Jul 28 2021 at 13:57)</a>:</h4>
<p>So to summarize, the following signatures for <a href="https://github.com/rust-lang/rust/blob/master/compiler/rustc_lexer/src/unescape.rs#L64"><code>unescape_literal</code></a> look like the best possibilities</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="c1">// 1</span>
<span class="k">fn</span> <span class="nf">unescape_literal</span><span class="o">&lt;</span><span class="n">F</span><span class="o">&gt;</span><span class="p">(</span><span class="n">literal_text</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span>: <span class="nc">Mode</span><span class="p">,</span><span class="w"> </span><span class="n">callback</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">F</span><span class="p">)</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="n">F</span>: <span class="nb">FnMut</span><span class="p">(</span><span class="n">Range</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="nb">Result</span><span class="o">&lt;</span><span class="nb">Result</span><span class="o">&lt;</span><span class="kt">char</span><span class="p">,</span><span class="w"> </span><span class="n">EscapeLint</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">EscapeError</span><span class="o">&gt;</span><span class="p">)</span><span class="w"></span>
<span class="c1">// 2</span>
<span class="k">enum</span> <span class="nc">EscapeResult</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="n">EscapedStringChar</span><span class="p">(</span><span class="kt">char</span><span class="p">),</span><span class="w"></span>
<span class="w">  </span><span class="n">EscapeLint</span><span class="p">(</span><span class="n">EscapeLint</span><span class="p">)</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">unescape_literal</span><span class="o">&lt;</span><span class="n">F</span><span class="o">&gt;</span><span class="p">(</span><span class="n">literal_text</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span>: <span class="nc">Mode</span><span class="p">,</span><span class="w"> </span><span class="n">callback</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">F</span><span class="p">)</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="n">F</span>: <span class="nb">FnMut</span><span class="p">(</span><span class="n">Range</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="nb">Result</span><span class="o">&lt;</span><span class="n">EscapeResult</span><span class="p">,</span><span class="w"> </span><span class="n">EscapeError</span><span class="o">&gt;</span><span class="p">)</span><span class="w"></span>
<span class="c1">// 3</span>
<span class="k">fn</span> <span class="nf">unescape_literal</span><span class="o">&lt;</span><span class="n">F</span><span class="p">,</span><span class="w"> </span><span class="n">G</span><span class="o">&gt;</span><span class="p">(</span><span class="n">literal_text</span>: <span class="kp">&amp;</span><span class="kt">str</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span>: <span class="nc">Mode</span><span class="p">,</span><span class="w"> </span><span class="n">emit_char</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">F</span><span class="p">,</span><span class="w"> </span><span class="n">emit_msg</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">G</span><span class="p">)</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="n">F</span>: <span class="nb">FnMut</span><span class="p">(</span><span class="kt">char</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="n">G</span>: <span class="nb">FnMut</span><span class="p">(</span><span class="n">Range</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="nb">Result</span><span class="o">&lt;</span><span class="n">EscapeLint</span><span class="p">,</span><span class="w"> </span><span class="n">EscapeError</span><span class="o">&gt;</span><span class="p">)</span><span class="w"></span>
</code></pre></div>
<p>I think (3) looks best but I'm not very experienced with Rust, so I'm not sure what the trade-offs are.</p>
<p>I'd be happy to implement this if it looks good ^^</p>
<p>Update: I've implemented version 1 here: <a href="https://github.com/rust-lang/rust/pull/87596">https://github.com/rust-lang/rust/pull/87596</a></p>



<a name="247814623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247814623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pierwill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247814623">(Jul 31 2021 at 17:07)</a>:</h4>
<p><span class="user-mention" data-user-id="428669">@Anton Golov</span>: You're welcome to work on this! I'm currently assigned, but I am thinking it's gotten out of my league. I can unassign myself if you like, and/or I help keep the convo going here :)</p>



<a name="247815785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/issue%2087319/near/247815785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Anton Golov <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/issue.2087319.html#247815785">(Jul 31 2021 at 17:35)</a>:</h4>
<p>Thanks for the update!  Sounds good, let me send a PR :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>